import React from 'react';
import { tp_list } from './cmd';
import { loc, KSwitch, KSelect, KRadioGroup, ck_sn, KRadio, obj_str, useKForm, ck_empty, KDlg, KInput } from 'sui';

const DlgVal = (props) => {
    const form = useKForm(props.data);

    const ck = {
        sn : v => ck_sn(v, props.data, props.main),
        name : v => ck_empty(v),
        tp : v => ck_empty(v),
        opt : v => {
            return null;
        },
        width : v => {
            return null;
        }
    };

    const isDis = () => {
        const set = props.set;
        if (!set) {
            return false;
        }

        const v = obj_str(props.data, "sn");
        if (!v) {
            return false;
        }

        if (set.has(v)) {
            return true;
        }

        return false;
    };

    return (
        <KDlg {...props} title={loc("l_191")} ck={ck} form={form}>
            <KInput label={loc("l_608")} form={form} name="sn" disabled={isDis()}/>
            <KInput label={loc("l_228")} form={form} name="name"/>
            <KInput label={loc("l_805")} form={form} name="width"/>
            <KSelect label={loc("l_229")} className="mt-4" form={form} name="tp" lst={tp_list()}/>
            <KSwitch className="mt-3" form={form} name="opt">{loc("l_218")}</KSwitch>
        </KDlg>
    );
};

const DlgMove = (props) => {
    const form = useKForm(props.data);

    const ck = {
        tp : v => ck_empty(v)
    };

    return (
        <KDlg {...props} title={loc("l_191")} ck={ck} form={form}>
            <KRadioGroup name="tp" form={form}>
                <KRadio value="up" label={loc("l_621")} />
                <KRadio value="down" label={loc("l_622")} />
            </KRadioGroup>
        </KDlg>
    );
};

const DlgProp = (props) => {
    const form = useKForm(props.data);

    const ck = {
        sn : v => ck_sn(v, props.data, props.main),
        name : v => ck_empty(v),
    };

    return (
        <KDlg {...props} title={loc("l_191")} ck={ck} form={form}>
            <KInput label={loc("l_608")} form={form} name="sn"/>
            <KInput label={loc("l_228")} form={form} name="name"/>
        </KDlg>
    );
};

export {DlgMove, DlgVal, DlgProp};
